package com.kuang.demo.controller.wx;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.wx.CommentBo;
import com.kuang.demo.bo.wx.OrderSubmitBo;
import com.kuang.demo.service.wx.WxCommentService;
import com.kuang.demo.service.wx.WxOrderService;
import com.kuang.demo.vo.wx.Goods4CommentVo;
import com.kuang.demo.vo.wx.OrderDetailVo;
import com.kuang.demo.vo.wx.OrderListVo;
import com.kuang.demo.vo.wx.OrderSubmitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    WxOrderService wxOrderService;
    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody OrderSubmitBo orderSubmitBo){
        int orderId = wxOrderService.submit(orderSubmitBo);
        if (orderId ==0){
            return BaseRespVo.fail("库存不足");
        }
        return BaseRespVo.fail("库存不足");
//        return BaseRespVo.ok(new OrderSubmitVo(orderId));
    }

    @RequestMapping("prepay")
    public BaseRespVo prepay(@RequestBody Map map){
//        Integer orderId = Integer.parseInt((String) map.get("orderId"));
////        wxOrderService.prepay(orderId);
////        //不让支付只能返回失败
        return BaseRespVo.fail("余额不足，请充值");
    }

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody CommentBo commentBo){
        wxOrderService.comment(commentBo);
        return BaseRespVo.ok();
    }
    @RequestMapping("list")
    public BaseRespVo list(@RequestParam Map map){
        OrderListVo orderListVo = wxOrderService.list(map);
        return BaseRespVo.ok(orderListVo);
    }
    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId){
        OrderDetailVo orderDetailVo = wxOrderService.detail(orderId);
        return BaseRespVo.ok(orderDetailVo);
    }
    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map){
        int orderId = (int) map.get("orderId");
        wxOrderService.cancel(orderId);
        return BaseRespVo.ok();
    }
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map map){
        int orderId = (int) map.get("orderId");
        wxOrderService.refund(orderId);
        return BaseRespVo.ok();
    }
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){
        int orderId = (int) map.get("orderId");
        wxOrderService.delete(orderId);
        return BaseRespVo.ok();
    }
    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map){
        int orderId = (int) map.get("orderId");
        wxOrderService.confirm(orderId);
        return BaseRespVo.ok();
    }
    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId, Integer goodsId){
        Goods4CommentVo goods4CommentVo = wxOrderService.goods(orderId,goodsId);
        return BaseRespVo.ok(goods4CommentVo);
    }

}
